package com.derek.omshopping.ui.home.present;

import android.content.Context;
import android.util.Log;

import com.derek.omshopping.bean.home.HomeIndexListAllBean;
import com.derek.omshopping.bean.home.HomeMainTypeBean;
import com.derek.omshopping.bean.home.HomeVideoBean;
import com.derek.omshopping.ui.home.contract.FragmentMainTypeListener;
import com.derek.omshopping.ui.home.contract.HomeIndexListener;
import com.derek.omshopping.ui.home.contract.HomeVideoListener;
import com.derek.omshopping.ui.home.model.FragmentMainTypeBizImpl;
import com.derek.omshopping.ui.home.view.IFragmentMainView;

import java.util.List;

/**
 * Created by duyb on 2016-10-17.
 * Desc:mvp p层
 * 1.持有model层和view层对象引用
 * 2.构造函数
 * 3.定义函调用model层具体函数 传递给view接口层
 */

public class FragmentMainTypePresenter {
    private FragmentMainTypeBizImpl fragmentMainTypeBiz;//model实现层
    private IFragmentMainView iFragmentMainView;//view接口层

    public FragmentMainTypePresenter(IFragmentMainView iFragmentMainView) {
        this.iFragmentMainView = iFragmentMainView;
        this.fragmentMainTypeBiz = new FragmentMainTypeBizImpl();
    }

    //调用model层数据
    public void loadData() {
        fragmentMainTypeBiz.LoadFragmentMainTypeData(new FragmentMainTypeListener() {

            @Override
            public void onSuccess(List<HomeMainTypeBean> list) {
                iFragmentMainView.sendToHomeTypeAdapter(list);
            }

            @Override
            public void onFailure(Exception e) {

            }
        });
    }

    //调用model层数据
    public void loadVideoData() {
        fragmentMainTypeBiz.LoadHomeVideoData(new HomeVideoListener() {
            @Override
            public void onSuccess(List<HomeVideoBean> list) {
                iFragmentMainView.sendToVideoAdapter(list);
            }

            @Override
            public void onFailure(Exception e) {

            }
        });
    }

    //调用model层数据
    public void loadIndexData() {
        fragmentMainTypeBiz.LoadHomeIndexData(new HomeIndexListener() {
            @Override
            public void onSuccess(List<HomeIndexListAllBean> list) {
                iFragmentMainView.sendToIndexAdapter(list);
            }

            @Override
            public void onFailure(Exception e) {
                Log.e("actvity-list-index","------------失败"+e.toString());
            }
        });
    }
    public void loadAllData(final Context context) {
        loadIndexData();
        loadData();
        loadVideoData();
    }
}
